package com.example.mall.order.app.cmd;

import com.example.mall.order.domain.constants.OrderType;
import com.example.mall.order.domain.model.Order;
import com.example.mall.order.domain.vo.MerchItem;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Mickey
 * @since 2022/4/22
 **/
@Data
public class CreateOrderCmd {

    private Long userId;
    private OrderType type;
    private List<Long> merchItemIds;

    public Order converterToOrder() {
        Order order = new Order();
        order.setUserId(userId);
        order.setFeeItems(new ArrayList<>());
        order.setStatus(0);
        order.setType(type);
        List<MerchItem> collect = merchItemIds
                .stream()
                .map(id -> new MerchItem("", id, BigDecimal.TEN))
                .collect(Collectors.toList());
        order.setMerchItems(collect);
        return order;
    }
}
